package com.example.demo.utils;

import java.util.HashMap;
import java.util.Map;

public class LayuiResult {


    private static Map<String,Object> result = null;

    public static Object LayuiData(Integer code,String msg,Object data,int... count){

        Map<String,Object> map = new HashMap<>();
        map.put("code",code);
        map.put("msg",msg);
        map.put("data",data);
        if(count != null){
            map.put("count",count);
        }
        return map;
    }


    public static Object addSuccess(){
        if(result == null){
            result = new HashMap<>();
        }
        result.put("msg",ResultMsg.ADD_SUCCESS);
        result.put("code",ResultCode.ADD_SUCCESS_CODE);
        return result;
    }

    public static Object deleteSuccess(){
        if(result == null){
            result = new HashMap<>();
        }
        result.put("msg",ResultMsg.DELETE_SUCCESS);
        result.put("code",ResultCode.DELETE_SUCCESS_CODE);
        return result;
    }

    public static Object selectSuccess(Object data,Integer... count){
        if(result == null){
            result = new HashMap<>();
        }
        result.put("msg",ResultMsg.SELECT_SUCCESS);
        result.put("code",ResultCode.SELECT_SUCCESS_CODE);
        result.put("data",data);
        if(count != null){
            result.put("count",count);
        }
        return result;
    }

    public static Object updateSuccess(){
        if(result == null){
            result = new HashMap<>();
        }
        result.put("msg",ResultMsg.UPDATE_SUCCESS);
        result.put("code",ResultCode.UPDATE_SUCCESS_CODE);
        return result;
    }


    public static Object searchSuccess(Object data,Integer... count){
        if(result == null){
            result = new HashMap<>();
        }
        result.put("msg",ResultMsg.SEARCH_SUCCESS);
        result.put("code",ResultCode.SELECT_SUCCESS_CODE);
        result.put("data",data);
        if(count != null){
            result.put("count",count);
        }
        return result;
    }


}
